
from flask import Flask, render_template, request, escape
from weather import weather_req,key
from viewlog import log_request

app = Flask(__name__)

@app.route('/results', methods=['POST','GET'])
def do_search() -> 'html':
    location = request.form['ID']
    title = '今天的天气是：'
    results = str(weather_req(key,location))
    log_request(request,results)
    return render_template('results.html',
                           the_title=title,
                           the_weather=results,
                           )
@app.route('/')

@app.route('/entry', methods=['POST','GET'])
def entry_page() -> 'html':
    title = '欢迎!'
    table_title= '请输入想要查询的地区：'
    return render_template('entry.html',
                           the_table_title=table_title,
                           the_title=title)


@app.route('/viewlog', methods=['POST','GET'])
def view_the_log() -> 'html':
    # 系统日志
    contents = []
    with open('viewlog.log', 'r') as log:
        for line in log:
            contents.append([])
            for item in line.split('|'):
                contents[-1].append(escape(item))
    len(contents)
    return render_template('viewlog.html',
                           the_title='系统日志',
                           the_data=contents)


if __name__ == '__main__':
    app.run(debug=True)






